
#if 0

#include "OSHeaders.h"
#include "log_api.h"
#include "fileops.h"

#include "QueueFile.h"



#define QUEUE_MaxSize	(m_queueFileHeader.u32MaxQSize)
#define QUEUE_Rear		(m_queueFileHeader.u32Rear)
#define QUEUE_Front		(m_queueFileHeader.u32Front)

#define File_RowSize	(m_queueFileHeader.u32RowSize)



QueueFile::QueueFile() :
	m_fileOps()
{
	memset(&m_queueFileHeader, 0x00, sizeof(TQueueFileHeader));
}

QueueFile::QueueFile(const char *filename, UInt32 capacity, UInt32 rowSize) :
	m_fileOps(filename, false)
{
	memset(&m_queueFileHeader, 0x00, sizeof(TQueueFileHeader));

	Open(filename, capacity, rowSize);
}


//if file exist,load header
//else file unexist, create header
bool QueueFile::Open(const char *filename, UInt32 rowSize)
{
	char header[sizeof(TQueueFileHeader)];
	SInt32 len = 0;
	OS_Error retVal = OS_NoErr;


	memset(&header, 0x00, sizeof(TQueueFileHeader));
	if (m_fileOps.Exists(filename))
	{
		//open
		if (!m_fileOps.IsOpened()){ m_fileOps.Open(filename, false); }

		//read header
		retVal = m_fileOps.Read(0, header, sizeof(TQueueFileHeader), len);
		if ((OS_NoErr != retVal) || (len != sizeof(TQueueFileHeader)))
		{
			m_fileOps.DelFile(filename);
			m_fileOps.Open(filename, false);
			memset(&m_queueFileHeader, 0x00, sizeof(TQueueFileHeader));
			m_queueFileHeader.u32MaxQSize ;
			m_queueFileHeader.u32RowSize = rowSize;
			retVal = m_fileOps.Write(0, header, sizeof(TQueueFileHeader), len);
			if ((OS_NoErr != retVal) || (len != sizeof(TQueueFileHeader)))
			{

				return false;
			}
		}
		else
		{
			memcpy(&m_queueFileHeader, header, len);
		}
	}
	else
	{

	}

	
	if (m_fileOps.IsOpened())return true;


	m_fileOps.Open(filename, false);

	retVal = m_fileOps.Read(0, header, sizeof(TQueueFileHeader), len);
	if ( (OS_NoErr != retVal) || (len != sizeof(TQueueFileHeader)) )
	{
		m_fileOps.DelFile(filename);
		m_fileOps.Open(filename, false);
		memset(&header, 0x00, sizeof(TQueueFileHeader));
		retVal = m_fileOps.Write(0, header, sizeof(TQueueFileHeader), len);
		if ((OS_NoErr != retVal) || (len != sizeof(TQueueFileHeader)))
		{
			return false;
		}
	}
	else
	{
		memcpy(&m_queueFileHeader, header, len);
	}

	return true;
}

//add
OS_Error QueueFile::EnQueue(UInt8 *buf, int len)
{
	UInt8 *rbuf = NULL;
	SInt32 wLen = 0;
	OS_Error retVal = OS_NoErr;
	UInt64 wPos = 0;


	if (NULL == buf || len != File_RowSize)
	{
		LOG_OUTPUT("Err:argument invalid\r\n");
		return OS_InvalidArgument;
	}

	if ((QUEUE_Rear + 1) % QUEUE_MaxSize == QUEUE_Front)
	{
		rbuf = (UInt8 *)calloc(1, File_RowSize);
		if (NULL != rbuf)
		{
			LOG_OUTPUT("Err:calloc failed\r\n");
			return OS_NotEnoughMem;
		}
		DeQueue(rbuf, File_RowSize);
		free(rbuf);
	}

	//write file
	wPos = QUEUE_Rear*File_RowSize;
	retVal = m_fileOps.Write(wPos, buf, len, wLen);
	if (retVal != OS_NoErr || wLen != File_RowSize)
	{
		LOG_OUTPUT("Err:wLen=%d,File_RowSize=%d\r\n", wLen, File_RowSize);
	}
	
	QUEUE_Rear = (QUEUE_Rear + 1) % QUEUE_MaxSize;

	return retVal;
}

//delete
OS_Error QueueFile::DeQueue(UInt8 *buf, int len)
{
	SInt32 rLen = 0;
	OS_Error retVal = OS_NoErr;
	UInt64 rPos = 0;


	if (NULL == buf || len != File_RowSize)
	{
		LOG_OUTPUT("Err:argument invalid\r\n");
		return OS_InvalidArgument;
	}

	if (QUEUE_Front == QUEUE_Rear)   return -1;

	//read file
	rPos = QUEUE_Front*File_RowSize;
	retVal = m_fileOps.Read(rPos, buf, len, rLen);
	if (retVal != OS_NoErr || rLen != File_RowSize)
	{
		LOG_OUTPUT("Err:rLen=%d,File_RowSize=%d\r\n", rLen, File_RowSize);
	}

	QUEUE_Front = (QUEUE_Front + 1) % QUEUE_MaxSize;

	return retVal;
}

//get
OS_Error QueueFile::GetElem(UInt32 pos, UInt8 *buf, int len)
{
	UInt64 rPos = 0;
	SInt32 rLen = 0;


	if ((pos < 0) || (pos >= QUEUE_MaxSize) || (NULL == buf) || (len != File_RowSize))
	{
		LOG_OUTPUT("Err:argument invalid,pos=%d\r\n", pos);
		return OS_InvalidArgument;
	}

	rPos = pos*File_RowSize;
	return m_fileOps.Read(rPos, buf, len, rLen);
}

//update
OS_Error QueueFile::SetElem(UInt32 pos, UInt8 *buf, int len)
{
	SInt32 wLen = 0;
	UInt64 wPos = 0;


	if ((pos < 0) || (pos >= QUEUE_MaxSize) || (NULL == buf) || (len != File_RowSize))
	{
		LOG_OUTPUT("Err:argument invalid,pos=%d\r\n", pos);
		return OS_InvalidArgument;
	}

	wPos = pos*File_RowSize;
	return m_fileOps.Read(wPos, buf, len, wLen);
}


void QueueFile::Close()
{
	m_fileOps.Close();
	memset(&m_queueFileHeader, 0x00, sizeof(TQueueFileHeader));
	return;
}


#endif


#if 0
template<class T>
Bool8 QueueFile<T>::Create(T model)
{
	sizeof(T);


	//write to file

	return true;
}

template<class T>
Bool8 QueueFile<T>::Update(T model)
{
	return true;
}

template<class T>
Bool8 QueueFile<T>::Delete(T model)
{
	return true;
}
#endif


